<template>
  <div>
    <!-- <h3>首页</h3> -->
    <el-container class="page">
      <el-aside width="200px">
        <!-- 左侧菜单栏 -->
        <el-menu
          default-active="1-1"
          class="el-menu-vertical-demo"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>

          <div v-for="item in info.menus" :key="item.id">
            <!-- 树型遍历 -->
            <el-submenu :index="item.id+''" v-if="item.children">
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{ item.title }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  :index="i.url"
                  v-for="i in item.children"
                  :key="i.id"
                  >{{ i.title }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>

            <!-- 普通遍历 -->
            <el-menu-item :index="item.url" v-else>
              <i class="el-icon-star-off"></i>
              <span slot="title">{{ item.title }}</span>
            </el-menu-item>
          </div>
        </el-menu>
      </el-aside>

      <el-container>
        <!-- 头部 -->
        <el-header>
          <div class="header-con">
            <span>{{ info.username }}</span>
            <el-button type="info" @click="logout">退出登录</el-button>
          </div>
        </el-header>
        <!-- 面包屑导航 -->
        <el-breadcrumb
          separator-class="el-icon-arrow-right"
          v-if="$route.meta.title"
        >
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
        </el-breadcrumb>

        <el-main>
          <!-- 二级路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
export default {
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    ...mapActions({
      changeInfo: "changeInfo",
    }),
    logout() {
      this.changeInfo({});
      this.$router.replace("/login");
    },
  },
  computed: {
    ...mapGetters({
      info: "info",
    }),
  },
};
</script>

<style scoped lang='less'>
@import "../../less/index.less";
/deep/ .el-menu {
  background: @middle !important;
}
/deep/.el-submenu__title:hover,
/deep/.el-menu-item:focus {
  background: @light !important;
}
/deep/.el-submenu__title,
/deep/.el-menu-item,
/deep/.el-menu-item {
  background: @middle !important;
}
.page {
  height: 100vh;
}
.el-aside {
  background: @middle;
}
.el-header {
  background: @light;
}
.header-con {
  float: right;
}
.header-con span {
  margin-top: @margin;
  margin-right: @margin;
  color: #fff;
}
.header-con .el-button {
  margin-top: @margin;
}
</style>